package problems;

import java.math.BigInteger;

import lib.Fraction;

public class Euler057 extends AbstractEuler {

	@Override
	public Number calculate() {
		int fractionsWithNumeratorWithMoreDigitsThanDenominator = 0;
		
		Fraction two = new Fraction(BigInteger.valueOf(2));
		Fraction half = new Fraction(1,2);

		Fraction expansion = half;
		for (int iterations = 2; iterations <= 1000; iterations++) {
			expansion = half.replaceDenominatorWith(two.plus(expansion));
			Fraction sqrt2 = expansion.plus(new Fraction(BigInteger.ONE)).normalized();
			if (sqrt2.getNumerator().toString().length() > sqrt2.getDenominator().toString().length()) fractionsWithNumeratorWithMoreDigitsThanDenominator++;
		}
		
		return fractionsWithNumeratorWithMoreDigitsThanDenominator;
	}

	
	@Override
	protected Number getCorrectAnswer() {
		return 153;
	}

}
